<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="./css/chooseGame.css">
    <title>2021少数民族传统体育竞技</title>
</head>

<body>
    <div class="layout">
        <img src="http://qrwbtqqjh.hn-bkt.clouddn.com/game1_9.png" alt="" class="bg-img">
        <img src="./img/back_btn.png" alt="" class="back-btn">
        <img src="./img/total_score.png" alt="" class="total-score">
        <p class="score">0</p>
        <div class="progress-box">
            <img src="./img/game1_26.png" alt="" class="line">
            <div class="progress-item game1">
                <img src="./img/file_3.png" alt="" class="project-img game1-img">
                <div class="score-box game1">
                    <span class="color-red">0分</span>
                    <img src="./img/game1_25.png" alt="">
                </div>
            </div>
            <div class="progress-item game2">
                <img src="./img/file_2.png" alt="" class="project-img game2-img">
                <div class="game2-score-box game2">
                    <span>未解锁</span>
                    <img src="./img/game1_23.png" alt="" class="progress-text-img">
                </div>
            </div>
            <div class="progress-item game3">
                <img src="./img/file_1.png" alt="" class="project-img game3-img">
                <div class="proigress-bottom-box">
                    <span>未解锁</span>
                    <img src="./img/game1_28.png" alt="" class="bamboo-active">
                </div>
            </div>
            <div class="progress-item gift-box">
                <img src="./img/grey_box.png" alt="" class="grey-box">
                <div class="text-box">
                    <p class="progress-desc">通关宝箱</p>
                </div>
            </div>
        </div>
    </div>


    <script src="./js/jquery.js"></script>
    <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="./js/arctext.js"></script>
    <script src="./js/request.js"></script>
    <script>
        request('get_share_sign/', {
            zm_token: localStorage.user_token,
            _zm_post_type: 'ajax',
            url: location.href
        }).then(res => {
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: res.rsm.appId, // 必填，公众号的唯一标识
                timestamp: res.rsm.timestamp, // 必填，生成签名的时间戳
                nonceStr: res.rsm.nonceStr, // 必填，生成签名的随机串
                signature: res.rsm.signature, // 必填，签名
                jsApiList: ['onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'onMenuShareQZone',
                    'onMenuShareTimeline',
                    'updateAppMessageShareData',
                    'hideOptionMenu',
                    'showOptionMenu',
                    'hideMenuItems',
                    'showMenuItems',
                    'hideAllNonBaseMenuItem',
                    'showAllNonBaseMenuItem',
                ] // 必填，需要使用的JS接口列表
            });
            
            wx.ready(function () { //需在用户可能点击分享按钮前就先调用
                wx.hideAllNonBaseMenuItem();
            });
        })
        let gameJson1 = JSON.parse(localStorage.getItem('game1')),
            gameJson2 = JSON.parse(localStorage.getItem('game2')),
            gameJson3 = JSON.parse(localStorage.getItem('game3')),
            totalScore
        request('refresh_settings/', {
            zm_token: localStorage.user_token,
            _zm_post_type: 'ajax'
        }).then(res => {
            let gameScore = res.rsm
            request('refresh_user_score/', {
                zm_token: localStorage.user_token,
                _zm_post_type: 'ajax'
            }).then(res => {
                // locMemory.localStorage.setItem('totalScore', res.rsm)
                totalScore = res.rsm
                // console.log(JSON.parse(getetItem('totalScore', res.rsm)));
                // 记得清除
                if (JSON.parse(localStorage.getItem('gift'))) {
                    $('.grey-box').attr('src', './img/success_box.png')
                }
                $('.game1 span').text(`${ res.rsm.tree_score}分`)
                if (gameJson1.active) {
                    $('.game2 span').addClass(gameJson1.active ? 'color-red' : '')
                    $('.game2 span').text(`${res.rsm.jump_score}分`)
                    $('.game2 .progress-text-img').attr('src', './img/game1_22.png')
                }
                if (gameJson2.active) {
                    $('.bamboo-active').attr('src', gameJson2.active ? './img/game1_27.png' :
                        './img/game1_28.png')
                    $('.game3 span').addClass(gameJson2.active ? 'color-red' : '')
                    $('.game3 span').text(`${res.rsm.dance_score}分`)
                }
                $('.score').text(`${ res.rsm.total_score}`)
                if (gameJson1.active && gameJson2.active && gameJson3.active && gameScore.total_score <= totalScore.total_score) {
                    if (localStorage.gift == 'true') {
                        $('grey-box').attr('src', './img/success_box.png')
                    } else {
                        $('.grey-box').attr('src', './img/yellow_box.png')
                    }
                    $('.grey-box').on('click', function () {
                        if (localStorage.gift == 'false') {
                            location.href = 'http://youxi.haiqikj.com/success.html'
                        }
                        // localStorage.setItem('gift', true)
                    })
                }
            })
        })



        // --------------------------------
        $('.back-btn').on('click', function () {
            location.href = 'http://youxi.haiqikj.com/index.html'
        })
        $('.progress-desc').arctext({
            radius: 120,
            dir: -1
        })
        // 第一个游戏
        $('.game1-img').on('click', function () {
            location.href = 'http://youxi.haiqikj.com/game1.html'
            // 记得清除
            localStorage.setItem('progress', 1)
        })
        // 第二个游戏
        $('.game2-img').on('click', function () {
            if (gameJson1.active) {
                location.href = 'http://youxi.haiqikj.com/game2.html'
            }
            // 记得清除
            localStorage.setItem('progress', 2)
        })
        // 第三个游戏
        $('.game3-img').on('click', function () {
            if (gameJson2.active) {
                location.href = 'http://youxi.haiqikj.com/game3.html'
            }
            // location.href = 'http://youxi.haiqikj.com/./game2.html'
            // 记得清除
            localStorage.setItem('progress', 3)
        })
    </script>
</body>

</html>